package com.iMusic.businessLogicLayer.testCase;


import java.sql.Date;
import java.sql.SQLException;
import java.util.Random;

import com.iMusic.businessLogicLayer.Account;
import com.iMusic.businessLogicLayer.Address;

import junit.framework.Assert;
import junit.framework.TestCase;

public class TestAccountCase extends TestCase{
	
	
	public void testCreateAccount(){
		
		Account account = new Account();
		Random random=new Random();
		int i = random.nextInt(10000); 
		String s = String.valueOf(i);
		System.out.println(i);
		System.out.println(s);
		account.setUsername("test"+s);
		account.setPasswd("test");
		account.setName("test");
		account.setSex("M");
		account.setBirthday( Date.valueOf("1980-01-01"));
		account.setEmail("test@gmail.com");
		account.setVip("off");
		account.setFinancialInstitution("CIBC");
		account.setCreditDirect("C");
		account.setAccountNumber("1234567890");
		account.setExpiryDate(Date.valueOf("2015-01-01"));
		Address address = new Address();
		address.setStreet("street");
		address.setStreetNbr("123");
		address.setComplement("123");
		address.setCity("Montreal");
		address.setProvince("QC");
		address.setPostalCode("H1H2H3");
		address.setCountry("Canada");
		account.setAddress(address);
		
		boolean test = false;
		try {
			test = account.createAccount();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Assert.assertEquals("Account should be create!", true, test);
	}

	
	public void testLoginCase1(){
		
		Account account = new Account();
		account.setUsername("test");
		account.setPasswd("test");
		account.setName("test");
		account.setSex("M");
		account.setBirthday( Date.valueOf("1980-01-01"));
		account.setEmail("test@gmail.com");
		account.setVip("off");
		account.setFinancialInstitution("CIBC");
		account.setCreditDirect("C");
		account.setAccountNumber("1234567890");
		account.setExpiryDate(Date.valueOf("2015-01-01"));
		Address address = new Address();
		address.setStreet("street");
		address.setStreetNbr("123");
		address.setComplement("123");
		address.setCity("Montreal");
		address.setProvince("QC");
		address.setPostalCode("H1H2H3");
		address.setCountry("Canada");
		account.setAddress(address);
		
		try {
			account.createAccount();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		boolean test = false;
		try {
			test = account.login();
			}
		catch (SQLException e) {
			e.printStackTrace();
		}
		Assert.assertEquals("login should be success!", true, test);
		//System.out.println("test="+test);
		
	}
	
	public void testLoginCase2(){
		
		Account account = new Account();
		account.setUsername("test");
		account.setPasswd("test1");
		boolean test = false;
		try {
			test = account.login();
			}
		catch (SQLException e) {
			e.printStackTrace();
		}
		Assert.assertEquals("login should not be success! -- The Wrong Password", false, test);
		//System.out.println("test="+test);
		
	}

	public void testLoginCase3(){
	
		Account account = new Account();
		account.setUsername("testtest");
		account.setPasswd("test");
		boolean test = false;
		try {
			test = account.login();
			}
		catch (SQLException e) {
			e.printStackTrace();
		}
		Assert.assertEquals("login should not be success! -- The user is not Exist", false, test);
		//System.out.println("test="+test);
	
	}
	
	public void testLogoutCase(){
		
		Account account = new Account();
		account.setUsername("test");
		account.setPasswd("test1");
		boolean test = false;
		try {
			account.login();
			test = account.logout();
			}
		catch (SQLException e) {
			e.printStackTrace();
		}
		Assert.assertEquals("login should be logout!", true, test);
		//System.out.println("test="+test);
		
	}
	
	
}
